

# generate appendix B, tables B1 and B2

library(rio) # to load data
library(tidyverse) # to reshape data
library(lmtest) # to cluster standard errors
library(sandwich) # to cluster standard errors
library(stargazer) # to generate tables

# set your working directory
setwd("~/replication_files")

monthly_data <- import("data/monthly_data.csv") %>%
  select(year,
         month,
         sovereign_issued_1yr,
         log_sovereign_issued_1yr_amount,
         noc_issued_1yr,
         log_noc_issued_1yr_amount,
         resource_rents_perc_lag,
         log_oil_production_lag,
         terms_of_trade_lag,
         discovery_lag,
         minister_is_econ_technocrat_usa,
         minister_turnover_5yrs,
         debt_crisis_experience,
         election_month,
         left_exec,fiscal_council,
         polcon,
         imf_agreement,
         fiscal_balance_lag,
         tax_perc_gdp_cepal_lag,
         log_core_inflation_lag,
         gdp_pc_cepal_lag,
         gdp_growth_cepal_lag,
         ka_open_lag,
         log_reserves_lag,
         treasury_rate_lag) %>%
  drop_na()

# table B1
stargazer(monthly_data,
          covariate.labels = c("Year","Month",
                               "Sovereign Issued = 1",
                               "Ln Sovereign Amount Issued",
                               "NOC Issued = 1",
                               "Ln NOC Amount Issued",
                               "Resource Rents, % of GDP $_{t-1}$",
                               "Ln Oil and Gas Production $_{t-1}$",
                               "Commodity Price Index $_{t-1}$",
                               "Field Discovery $_{t-1}$",
                               "Mainstream Minister = 1",
                               "Minister Turnover (5 Years)",
                               "Debt Crisis Experience = 1",
                               "Election Month = 1",
                               "Left Executive = 1",
                               "Fiscal Council = 1",
                               "Political Constraints",
                               "IMF Agreement = 1",
                               "Fiscal Balance, % of GDP $_{t-1}$",
                               "Tax Revenue, % of GDP $_{t-1}$",
                               "Ln Core Inflation $_{t-1}$",
                               "GDP Per Capita $_{t-1}$",
                               "GDP Growth, % $_{t-1}$",
                               "Capital Openness $_{t-1}$",
                               "Ln International Reserves $_{t-1}$",
                               "US Treasury Rate, % $_{t-1}$"))


annual_data <- import("data/annual_data.csv") %>%
  select(year,
         log_ratio_multilateral_bonds_delta,
         log_ratio_bilateral_bonds_delta,
         log_ratio_commercial_banks_bonds_delta,
         resource_rents_perc_delta,
         log_oil_production_delta,
         terms_of_trade_delta,
         discovery_lag,
         minister_is_econ_technocrat_usa, 
         minister_turnover_5yrs,
         debt_crisis_experience,
         election_year, left_exec,
         fiscal_council,polcon,
         imf_agreement, 
         fiscal_balance_lag,
         tax_perc_gdp_cepal_lag,
         log_core_inflation_lag,
         gdp_pc_cepal_lag, 
         gdp_growth_cepal_lag, 
         ka_open_lag, 
         log_reserves_lag,
         treasury_rate_lag) %>%
  drop_na()

# table B2
stargazer(annual_data,
          covariate.labels = c("Year",
                               "Ln (Multilateral to Bonds) $_{Delta}$",
                               "Ln (Bilateral to Bonds) $_{Delta}$",
                               "Ln (Commercial Banks to Bonds) $_{Delta}$",
                               "Resource Rents, % of GDP $_{Delta}$",
                               "Ln Oil and Gas Production $_{Delta}$",
                               "Commodity Price Index $_{Delta}$",
                               "Field Discovery $_{t-1}$",
                               "Mainstream Minister = 1",
                               "Minister Turnover (5 Years)",
                               "Debt Crisis Experience = 1",
                               "Election Year = 1",
                               "Left Executive = 1",
                               "Fiscal Council = 1",
                               "Political Constraints",
                               "IMF Agreement = 1",
                               "Fiscal Balance, % of GDP $_{t-1}$",
                               "Tax Revenue, % of GDP $_{t-1}$",
                               "Ln Core Inflation $_{t-1}$",
                               "GDP Per Capita $_{t-1}$",
                               "GDP Growth, % $_{t-1}$",
                               "Capital Openness $_{t-1}$",
                               "Ln International Reserves $_{t-1}$",
                               "US Treasury Rate, % $_{t-1}$"))
